package com.liz.rpcserver.controller;

import com.liz.lizrpcapi.commons.Node;
import com.liz.lizrpcapi.entity.RegisterEntity;
import com.liz.rpcserver.commons.GlobalHolder;
import com.liz.rpcserver.service.RegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author liangGongWei
 * @description
 * @create 2021-08-23 17:39
 **/

@Slf4j
@RestController
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    @PostMapping(value = "/liz/rpc/register")
    public void providerRegister(@RequestBody RegisterEntity entity){
        log.info("接口访问：/liz/rpc/register,data:{}",entity);
        this.registerService.register(entity);
    }

    @GetMapping (value = "/liz/rpc/getClassMap")
    Map<String, Set<String>> getClassName(){
        log.info("接口访问：/liz/rpc/getClassMap");
        return GlobalHolder.providerClientMap;
    }

    @GetMapping (value = "/liz/rpc/getMethodMap")
    Map<String, Set<String>> getMethodMap(){
        log.info("接口访问：/liz/rpc/getMethodMap");
        return GlobalHolder.providerMethodMap;
    }


    @GetMapping(value = "/liz/rpc/remote-class-node")
    public Map<String, Map<String,Node>> remoteClassNode(){
        log.info("接口访问：/liz/rpc/remote-class-node");
        return GlobalHolder.classNodeMap;
    }
}
